package com.itheima.d4_arrays;

public class Student implements Comparable<Student> {

    @Override
    public int compareTo(Student o) {
        //重写的方法：用来制定排序规则
        //升序：当前要存的 - 里面已有的，得到正数结果返回！

        //1.调用compareTo方法一定是Student对象！参数传入的也是Student对象，这就是两个学生对象，让他们俩做减法
        //需求：按年龄升序，获取两个学生对象的年龄
        //this：是当前要存的学生对象
        int age1 = this.getAge();
        //o：容器中已有的学生对象
        int age2 = o.getAge();

        //年龄相减，得到整数结果
        int result = age1 - age2;

        return result;
    }

    private String name;
    private double height;
    private int age;

    public Student(String name, double height, int age) {
        this.name = name;
        this.height = height;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", height=" + height +
                ", age=" + age +
                '}';
    }
}
